﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using DevExpress.XtraCharts;
using System.Drawing.Imaging;
using DrugsShopManagement.DBCLASS;

namespace DrugsShopManagement
{
    public partial class XtraFrmStatistics : DevExpress.XtraEditors.XtraForm
    {
        public XtraFrmStatistics()
        {
            InitializeComponent();
        }
        #region //代码
        
        #region //创建ChartStatisticsPreviewAndPrintHelper类的实例，该实例用于xtraCharts的预览以及打印
        ChartStatisticsPreviewAndPrintHelper p = new ChartStatisticsPreviewAndPrintHelper();
        #endregion

        #region//XtraFrmStatistics_Load事件
        private void XtraFrmStatistics_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dataSetDrugsName.drugsInfo”中。您可以根据需要移动或删除它。
            this.drugsInfoTableAdapter.Fill(this.dataSetDrugsName.drugsInfo);

            // TODO: 这行代码将数据加载到表“salesIncreasingDataSet.drugsSales”中。您可以根据需要移动或删除它。
            this.drugsSalesTableAdapter1.Fill(this.salesIncreasingDataSet.drugsSales);  

            // TODO: 这行代码将数据加载到表“dataSetUsers.users”中。您可以根据需要移动或删除它。
            this.drugsSalesTableAdapter.Fill(this.drugssale.drugsSales);

            //以下代码功能是对dateTimePicker的值进行调节
            this.dateTimePicker2.Value = this.dateTimePicker1.Value;
            this.dateTimePicker4.Value = this.dateTimePicker3.Value;
            this.dateTimePicker6.Value = this.dateTimePicker5.Value;
            this.dateTimePicker8.Value = this.dateTimePicker7.Value;
            this.dateTimePicker10.Value = this.dateTimePicker9.Value;
            this.dateTimePicker12.Value = this.dateTimePicker11.Value;
            this.dateTimePicker14.Value = this.dateTimePicker13.Value;
            this.dateTimePicker16.Value = this.dateTimePicker15.Value;
            this.dateTimePicker18.Value = this.dateTimePicker17.Value;
            this.dateTimePicker20.Value = this.dateTimePicker19.Value;
            this.dateTimePicker1.Value = this.dateTimePicker2.Value.AddMonths(-1);
            this.dateTimePicker3.Value = this.dateTimePicker4.Value.AddMonths(-1);
            this.dateTimePicker5.Value = this.dateTimePicker6.Value.AddMonths(-1);
            this.dateTimePicker7.Value = this.dateTimePicker8.Value.AddMonths(-1);
            this.dateTimePicker9.Value = this.dateTimePicker10.Value.AddMonths(-1);
            this.dateTimePicker11.Value = this.dateTimePicker12.Value.AddMonths(-1);
            this.dateTimePicker13.Value = this.dateTimePicker14.Value.AddMonths(-1);
            this.dateTimePicker15.Value = this.dateTimePicker16.Value.AddMonths(-1);
            this.dateTimePicker17.Value = this.dateTimePicker18.Value.AddMonths(-1);
            this.dateTimePicker19.Value = this.dateTimePicker20.Value.AddMonths(-1);
        }
        #endregion

        #region //navBarControl的navBarItem链接到指定xtraTabPage
        private void navBarItem1_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //if (xtraForm1 == null || xtraForm1.IsDisposed)
            //{
            //    xtraForm1 = new XtraForm1();
            //    xtraForm1.Show();
            //}
            //if (xtraForm1 != null)
            //{
            //    xtraForm1.Activate();
            //}
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage1;
            this.xtraTabControl2.SelectedTabPage = this.xtraTabPage4;
        }

        private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage1;
            this.xtraTabControl2.SelectedTabPage = this.xtraTabPage5;
        }

        private void navBarItem3_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage1;
            this.xtraTabControl2.SelectedTabPage = this.xtraTabPage6;
        }

        private void navBarItem4_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage2;
            this.xtraTabControl3.SelectedTabPage = this.xtraTabPage7;
        }

        private void navBarItem5_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage2;
            this.xtraTabControl3.SelectedTabPage = this.xtraTabPage8;
        }

        private void navBarItem6_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage2;
            this.xtraTabControl3.SelectedTabPage = this.xtraTabPage9;
        }

        private void navBarItem7_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage3;
            this.chartControl4.SelectedTabPage = this.xtraTabPage10;
        }

        private void navBarItem8_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage3;
            this.chartControl4.SelectedTabPage = this.xtraTabPage11;
        }

        private void navBarItem9_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage3;
            this.chartControl4.SelectedTabPage = this.xtraTabPage12;
        }

        private void navBarItem10_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage3;
            this.chartControl4.SelectedTabPage = this.xtraTabPage13;
        }

        private void navBarItem11_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage3;
            this.chartControl4.SelectedTabPage = this.xtraTabPage14;
        }
        #endregion

        #region //按入库数量统计、预览、打印
        private void DrugsInCountStatistics_Click(object sender, EventArgs e)
        {
            //按入库数量分析统计
        }

        private void DrugsInCountPreview_Click(object sender, EventArgs e)
        {
            //按入库数量分析预览
            p.ShowChartPreview(chartControlDrugsInCount, chartControlDrugsInCount.Width, chartControlDrugsInCount.Height);
        }

        private void DrugsInCountPrint_Click(object sender, EventArgs e)
        {
            //按入库数量分析打印
            p.PrintChart(chartControlDrugsInCount, chartControlDrugsInCount.Width, chartControlDrugsInCount.Height);
        }
        #endregion
        #region //按入库日期统计、预览、打印
        private void DrugsInDateStatistics_Click(object sender, EventArgs e)
        {
            //按入库日期分析统计
        }

        private void DrugsInDatePriview_Click(object sender, EventArgs e)
        {
            //按入库日期分析预览
            p.ShowChartPreview(chartControlDrugsInDate, chartControlDrugsInDate.Width, chartControlDrugsInDate.Height);
        }

        private void DrugsInDatePrint_Click(object sender, EventArgs e)
        {
            //按入库日期分析打印
            p.PrintChart(chartControlDrugsInDate, chartControlDrugsInDate.Width, chartControlDrugsInDate.Height);
        }
        #endregion
        #region //按入库药品统计、预览、打印
        private void DrugsInNameStatistics_Click(object sender, EventArgs e)
        {
            //按入库药品分析统计
        }

        private void DrugsInNamePreview_Click(object sender, EventArgs e)
        {
            //按入库药品分析预览
            p.ShowChartPreview(chartControlDrugsInName, chartControlDrugsInName.Width, chartControlDrugsInName.Height);
        }

        private void DrugsInNamePrint_Click(object sender, EventArgs e)
        {
            //按入库药品分析打印
            p.PrintChart(chartControlDrugsInName, chartControlDrugsInName.Width, chartControlDrugsInName.Height);
        }
        #endregion

        #region //按出库数量统计、预览、打印
        private void DrugsOutCountStatistics_Click(object sender, EventArgs e)
        {
            //按出库数量分析统计
        }

        private void DrugsOutCountPreview_Click(object sender, EventArgs e)
        {
            //按出库数量分析预览
            p.ShowChartPreview(chartControlDrugsOutCount, chartControlDrugsOutCount.Width, chartControlDrugsOutCount.Height);
        }

        private void DrugsOutCountPrint_Click(object sender, EventArgs e)
        {
            //按出库数量分析打印
            p.PrintChart(chartControlDrugsOutCount, chartControlDrugsOutCount.Width, chartControlDrugsOutCount.Height);
        }
        #endregion
        #region //按出库日期统计、预览、打印
        private void DrugsOutDateStatistics_Click(object sender, EventArgs e)
        {
            //按出库日期分析统计
        }

        private void DrugsOutDatePriview_Click(object sender, EventArgs e)
        {
            //按出库日期分析预览
            p.ShowChartPreview(chartControlDrugsOutDate, chartControlDrugsOutDate.Width, chartControlDrugsOutDate.Height);
        }

        private void DrugsOutDatePrint_Click(object sender, EventArgs e)
        {
            //按出库日期分析打印
            p.PrintChart(chartControlDrugsOutDate, chartControlDrugsOutDate.Width, chartControlDrugsOutDate.Height);
        }
        #endregion
        #region //按出库药品统计、预览、打印
        private void DrugsOutNameStatistics_Click(object sender, EventArgs e)
        {
            //按出库药品分析统计
        }

        private void DrugsOutNamePreview_Click(object sender, EventArgs e)
        {
            //按出库药品分析预览
            p.ShowChartPreview(chartControlDrugsOutName, chartControlDrugsOutName.Width, chartControlDrugsOutName.Height);
        }

        private void DrugsOutNamePrint_Click(object sender, EventArgs e)
        {
            //按出库药品分析打印
            p.PrintChart(chartControlDrugsOutName, chartControlDrugsOutName.Width, chartControlDrugsOutName.Height);
        }
        #endregion

        #region//销售增长趋势分析统计、预览、打印
        private void DrugsSalesIncreasingStatistics_Click(object sender, EventArgs e)
        {
            //比较时间（ 开始时间不能大于结束时间 ） 
            p.CompareTime(this.dateTimePicker3, this.dateTimePicker4);

            // 创建新的data filters 和 specify conditions
            DataFilter dataFilter1 = new DataFilter("drugsSalesTime", "System.DateTime", DataFilterCondition.GreaterThanOrEqual, dateTimePicker3.Text.ToString());
            DataFilter dataFilter2 = new DataFilter("drugsSalesTime", "System.DateTime", DataFilterCondition.LessThanOrEqual, dateTimePicker4.Text.ToString());

            DataFilter dataFilter3 = new DevExpress.XtraCharts.DataFilter("drugsId", "System.Int32", DevExpress.XtraCharts.DataFilterCondition.Equal, 10002);
            DataFilter dataFilter4 = new DevExpress.XtraCharts.DataFilter("drugsId", "System.Int32", DevExpress.XtraCharts.DataFilterCondition.Equal, 10003);

            //if (this.textBox1.Text.Trim() != "")
            //{
            //    DataFilter dataFilter5 = new DevExpress.XtraCharts.DataFilter("drugsId", "System.Int32", DevExpress.XtraCharts.DataFilterCondition.Equal, this.textBox1.Text.Trim());

            //    DevExpress.XtraCharts.Series series3 = new DevExpress.XtraCharts.Series();
            //    ((System.ComponentModel.ISupportInitialize)(series3)).BeginInit();
            //    series3.ArgumentDataMember = "drugsSalesTime";
            //    series3.ArgumentScaleType = DevExpress.XtraCharts.ScaleType.DateTime;
            //    //series3.Label = pointSeriesLabel1;
            //    series3.Name = "666666";
            //    series3.SummaryFunction = "SUM([drugsSalesNum])";
            //    //series3.View = lineSeriesView1;
            //    ((System.ComponentModel.ISupportInitialize)(series3)).EndInit();

            //    series3.DataFiltersConjunctionMode = ConjunctionTypes.And;
            //    series3.DataFilters.Clear();
            //    series3.DataFilters.AddRange(new DataFilter[] { dataFilter1, dataFilter2, dataFilter5 });

            //}

            // Obtain the first series of the chart.
            Series series1 = chartControlDrugsSaleIncreasing.Series[0];
            Series series2 = chartControlDrugsSaleIncreasing.Series[1];

            // Set the logical operator used to combine individual data filter conditions for this series.
            series1.DataFiltersConjunctionMode = ConjunctionTypes.And;
            series2.DataFiltersConjunctionMode = ConjunctionTypes.And;

            // 移除现有filters.
            series1.DataFilters.Clear();
            series2.DataFilters.Clear();

            // 添加新的filters应用到series data
            series1.DataFilters.AddRange(new DataFilter[] { dataFilter1, dataFilter2, dataFilter4 });
            series2.DataFilters.AddRange(new DataFilter[] { dataFilter1, dataFilter2, dataFilter3 });
        }

        private void DrugsSalesIncreasingPreview_Click(object sender, EventArgs e)
        {
            //销售增长分析预览
            p.ShowChartPreview(chartControlDrugsSaleIncreasing, chartControlDrugsSaleIncreasing.Width, chartControlDrugsSaleIncreasing.Height);
        }

        private void DrugsSalesIncreasingPrint_Click(object sender, EventArgs e)
        {
            //销售增长分析打印
            p.PrintChart(chartControlDrugsSaleIncreasing, chartControlDrugsSaleIncreasing.Width, chartControlDrugsSaleIncreasing.Height);
        }
#endregion
        #region//畅销药品分析统计、预览、打印
        private void DrugsSalesGoodStatistics_Click(object sender, EventArgs e)
        {
            //比较时间（ 开始时间不能大于结束时间 ） 
            p.CompareTime(this.dateTimePicker1, this.dateTimePicker2);

            // Create new data filters and specify conditions for them.
            DataFilter dataFilter1 = new DataFilter("drugsSalesTime", "System.DateTime", DataFilterCondition.GreaterThanOrEqual, dateTimePicker1.Text.ToString());
            DataFilter dataFilter2 = new DataFilter("drugsSalesTime", "System.DateTime", DataFilterCondition.LessThanOrEqual, dateTimePicker2.Text.ToString());

            // Obtain the first series of the chart.
            Series series1 = chartControlDrugsSalesGood.Series[0];

            // Set the logical operator used to combine individual data filter conditions for this series.
            series1.DataFiltersConjunctionMode = ConjunctionTypes.And;

            // Remove all other filters.
            series1.DataFilters.Clear();

            // Add new filters to apply to the series data.
            series1.DataFilters.AddRange(new DataFilter[] { dataFilter1, dataFilter2 });


            //// TODO: 这行代码将数据加载到表“drugssale.drugsSales”中。您可以根据需要移动或删除它。
            //this.drugsSalesTableAdapter1.Fill(this.drugssale.drugsSales);
        }

        private void DrugsSalesGoodPreview_Click(object sender, EventArgs e)
        {
            //畅销药品分析预览
            p.ShowChartPreview(chartControlDrugsSalesGood, chartControlDrugsSalesGood.Width, chartControlDrugsSalesGood.Height);
        }

        private void DrugsSalesGoodPrint_Click(object sender, EventArgs e)
        {
            //畅销药品分析打印
            p.PrintChart(chartControlDrugsSalesGood, chartControlDrugsSalesGood.Width, chartControlDrugsSalesGood.Height);
        }
        #endregion
        #region//滞销药品分析统计、预览、打印
        private void DrugsSalesBadStatistics_Click(object sender, EventArgs e)
        {
            //滞销药品分析统计
        }

        private void DrugsSalesBadPreview_Click(object sender, EventArgs e)
        {
            //滞销药品分析预览
            p.ShowChartPreview(chartControlDrugsSalesBad, chartControlDrugsSalesBad.Width, chartControlDrugsSalesBad.Height);
        }

        private void DrugsSalesBadPrint_Click(object sender, EventArgs e)
        {
            //滞销药品分析打印
            p.PrintChart(chartControlDrugsSalesBad, chartControlDrugsSalesBad.Width, chartControlDrugsSalesBad.Height);
        }
        #endregion
        #region //销售总数量分析统计、预览、打印
        private void DrugsSalesCountStatistics_Click(object sender, EventArgs e)
        {
            //销售总数量分析统计

            //比较时间（ 开始时间不能大于结束时间 ） 
            p.CompareTime(this.dateTimePicker5, this.dateTimePicker6);

            // Create new data filters and specify conditions for them.
            DataFilter dataFilter1 = new DataFilter("drugsSalesTime", "System.DateTime", DataFilterCondition.GreaterThanOrEqual, dateTimePicker5.Text.ToString());
            DataFilter dataFilter2 = new DataFilter("drugsSalesTime", "System.DateTime", DataFilterCondition.LessThanOrEqual, dateTimePicker6.Text.ToString());

            // Obtain the first series of the chart.
            Series series1 = chartControlDrugsSalesCount.Series[0];

            // Set the logical operator used to combine individual data filter conditions for this series.
            series1.DataFiltersConjunctionMode = ConjunctionTypes.And;

            // Remove all other filters.
            series1.DataFilters.Clear();

            // Add new filters to apply to the series data.
            series1.DataFilters.AddRange(new DataFilter[] { dataFilter1, dataFilter2 });
        }

        private void DrugsSalesCountPreview_Click(object sender, EventArgs e)
        {
            //销售总数量分析预览
            p.ShowChartPreview(chartControlDrugsSalesCount, chartControlDrugsSalesCount.Width, chartControlDrugsSalesCount.Height);
        }

        private void DrugsSalesCountPrint_Click(object sender, EventArgs e)
        {
            //销售总数量分析打印
            p.PrintChart(chartControlDrugsSalesCount, chartControlDrugsSalesCount.Width, chartControlDrugsSalesCount.Height);
        }
        #endregion
        #region //销售总金额分析统计、预览、打印
        private void DrugsSalesMoneyStatistics_Click(object sender, EventArgs e)
        {
            //销售总金额分析统计
        }

        private void DrugsSalesMoneyPreview_Click(object sender, EventArgs e)
        {
            //销售总金额分析预览
            p.ShowChartPreview(chartControlDrugsSalesMoney, chartControlDrugsSalesMoney.Width, chartControlDrugsSalesMoney.Height);
        }

        private void DrugsSalesMoneyPrint_Click(object sender, EventArgs e)
        {
            //销售总金额分析打印
            p.PrintChart(chartControlDrugsSalesMoney, chartControlDrugsSalesMoney.Width, chartControlDrugsSalesMoney.Height);
        }
        #endregion

        #region //gridControl2_Click事件，把gridView的值传到textBox
        private void gridControl2_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = this.gridView2.GetFocusedRowCellValue("drugsId").ToString();
            this.textBox2.Text = this.gridView2.GetFocusedRowCellValue("drugsName").ToString();
        }
        #endregion

        #endregion
    }
}
